package top.kaoshanji.ch03;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Scanner;

/**
 * 代码清单 ch03-03：while示例(计算养老金1)
 * author kaoshanji
 * ^_^
 * create time 2024/11/23 18:25
 */
public class Retirement {

    private static final Logger logger = LogManager.getLogger(Retirement.class);

    public static void main(String[] args) {
        logger.info("...代码清单 ch03-03：while示例(计算养老金1)...");

        Scanner in = new Scanner(System.in);

        System.out.print("How much money do you need to retire? ");
        double goal = in.nextDouble();

        System.out.print("How much money will you contribute every year? ");
        double payment = in.nextDouble();

        System.out.print("Interest rate in %: ");
        double interestRate = in.nextDouble();


        double balance = 0;
        int years = 0;

        while (balance < goal) {
            balance += payment;
            double interest = balance * interestRate / 100;
            balance += interest;
            years++;
        }

        System.out.println("You can retire in " + years + " years.");
    }

}
